from flask import Blueprint, request, jsonify
import random
import string
from datetime import datetime, timedelta

users_bp = Blueprint('users', __name__)

def random_string(length=10):
    return ''.join(random.choices(string.ascii_letters, k=length))

def random_time():
    now = datetime.now()
    delta = timedelta(days=random.randint(0, 30), 
                      hours=random.randint(0, 23),
                      minutes=random.randint(0, 59))
    return (now - delta).strftime('%Y-%m-%d %H:%M:%S')

@users_bp.route('/', methods=['GET'])
def get_user_list():
    page_id = request.args.get('page_id', 1)
    
    users = []
    for _ in range(10):
        users.append({
            'user_id': random_string(),
            'bu': random_string(2).upper(),
            'email': f"{random_string(8)}@example.com",
            'enable_time': random_time(),
            'disable_time': random_time(),
            'queued_tasks': random.randint(3, 30),
            'running_tasks': random.randint(3, 30),
            'is_enabled': random.choice([0, 1])
        })
    
    return jsonify({'users': users})
